﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Demo.Framework.Algorithm.Sort
{
    class Program
    {
        static void Main(string[] args)
        {
            // Selection sort
            int[] a1 = new int[] { 3, 2, 15, -4, 7, 0, 9 };
            Console.WriteLine("***** Selection Sort *****");
            Console.WriteLine("Unsorted array : " + PrintArray(a1));
            SelectionSort<int> selectionSort = new SelectionSort<int>();
            selectionSort.Sort(a1);
            Console.WriteLine("Sorted array : " + PrintArray(a1));

            // Insertion sort
            int[] a2 = new int[] { 3, 2, 15, -4, 7, 0, 9 };
            Console.WriteLine("***** Insertion Sort *****");
            Console.WriteLine("Unsorted array : " + PrintArray(a2));
            SelectionSort<int> insertionSort = new SelectionSort<int>();
            insertionSort.Sort(a2);
            Console.WriteLine("Sorted array : " + PrintArray(a2));

            // Shell sort
            int[] a3 = new int[] { 3, 2, 15,-4, 7, 0, 9 };
            Console.WriteLine("***** Shell Sort *****");
            Console.WriteLine("Unsorted array : " + PrintArray(a3));
            SelectionSort<int> shellSort = new SelectionSort<int>();
            insertionSort.Sort(a3);
            Console.WriteLine("Sorted array : " + PrintArray(a3));

            // Merge sort
            int[] a4 = new int[] { 3, 2, 15, -4, 7, 0, 9 };
            Console.WriteLine("***** Merge Sort ******");
            Console.WriteLine("Unsorted array : " + PrintArray(a4));
            SelectionSort<int> mergeSort = new SelectionSort<int>();
            insertionSort.Sort(a4);
            Console.WriteLine("Sorted array : " + PrintArray(a4));

            Console.Read();
        }

        private static string PrintArray<T>(T[] array)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < array.Length; i++)
            {
                if (i< array.Length-1)
                    sb.Append(array[i] + ", ");
                else
                    sb.Append(i);
            }
            return sb.ToString();
        }
    }
}
